<template>
    <div class="wrapper-login">
       <el-form :model="form" >
            <el-form-item label="用户名">
                <el-input v-model="form.userName"/>
            </el-form-item>
            <el-form-item label="密码">
                <el-input type="password" v-model="form.password" />
            </el-form-item>
       </el-form>
       <el-button type="primary" @click="Login">登录</el-button>
    </div>
</template>

<script>
import md5 from 'js-md5';
import {ref,reactive} from 'vue'
import {login} from '../api/user'
import {useRouter} from 'vue-router'

export default {
    setup(props) {
        const router = useRouter();
        const form=reactive({
            userName:'admin',
            password:'123456'
        })
        
        const Login=()=>{
            const passwordMd5 =md5(form.password)
            console.log(passwordMd5);
            console.log(form);
            login({userName:form.userName,passwordMd5:md5(form.password)}).then(res=>{
                console.log(res);
                if(res.resultCode=='200'){
                    router.push('/home')
                    console.log(res.data);
                    localStorage.setItem('token',res.data)
                }else{
                    alert('登陆失败！')
                }
            })
        }

        return{
            form,
            Login
        }
    }
}
</script>

<style lang="scss" scoped>
.wrapper-login {
  width: 500px;
  height: 200px;
  border: 1px solid #ccc;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 40px;
  box-sizing: border-box;
  text-align: center;
  border-radius: 10px;
}
</style>